<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="/html/portlet/chart/view/init.jsp"%>

<portlet:defineObjects />
<%
Option selOption = null;
try{
	if(Validator.isNotNull(chart_view_optionid)){
		selOption = OptionLocalServiceUtil.getOption(chart_view_optionid);
	}
}
catch (NoSuchOptionException nsrse) {
}
%>
<liferay-portlet:actionURL portletConfiguration="true" var="configurationActionURL" />
<liferay-portlet:renderURL portletConfiguration="true" varImpl="configurationRenderURL" />
<aui:form action="<%= configurationActionURL %>" method="post" name="fm">
<liferay-ui:tabs names="chart.config,chart.theme"
	refresh="<%=false%>">
<liferay-ui:section>
	<liferay-ui:error-marker key="errorSection" value="chart.config" />
	<div class="alert alert-info">
		<span class="displaying-help-message-holder <%=selOption == null ? StringPool.BLANK : "hide"%>">
			<liferay-ui:message key="chart.view.config.select.option.from.list" />
		</span> 
		<span class="displaying-chart-option-id-holder <%= selOption == null ? "hide" : StringPool.BLANK %>">
			<liferay-ui:message key="chart.view.config.displaying.option" />: <span class="displaying-chart-option-id"><%= selOption != null ? selOption.getName() : StringPool.BLANK %></span>
		</span>
	</div>
		<liferay-ui:search-container>
			<liferay-ui:search-container-results
					results="<%=OptionLocalServiceUtil.getOptions(searchContainer.getStart(), searchContainer.getEnd())%>"
					total="<%= OptionLocalServiceUtil.getOptionsCount() %>" />
			
			<liferay-ui:search-container-row
				className="cn.shuto.liferay.plugin.chart.service.model.Option"
				keyProperty="optionId" modelVar="option" escapedModel="<%=true%>">
				<%
					StringBundler sb = new StringBundler(7);
	
					sb.append("javascript:");
					sb.append(renderResponse.getNamespace());
					sb.append("selectRecordSet('");
					sb.append(option.getOptionId());
					sb.append("','");
					sb.append(option.getName());
					sb.append("');");
	
					String rowURL = sb.toString();
				%>
				<liferay-ui:search-container-column-text href="<%= rowURL %>" name="chart.option.id"
					property="optionId" />
				<liferay-ui:search-container-column-text href="<%= rowURL %>" name="name"/>
				<liferay-ui:search-container-column-text href="<%= rowURL %>" name="description"/>
				<liferay-ui:search-container-column-date href="<%= rowURL %>" name="modified-date" property="modifiedDate"/>
				<liferay-ui:search-container-column-text href="<%= rowURL %>" name="author" property="userName"/>
				<liferay-ui:search-container-column-date href="<%= rowURL %>" name="create-date" property="createDate"/>
			</liferay-ui:search-container-row>
			<liferay-ui:search-iterator />
		</liferay-ui:search-container>
<!--<div class="separator"> </div-->

	<aui:fieldset >
			<aui:input name="portletId" type="resource" value="<%= portletResource %>" />
			<div class="field-row">
					<aui:input type="number" inlineField="<%=true %>" label="chart.view.height" name="preferences--chart_view_height--" value="<%= chart_view_height %>" />
					<aui:select  name="preferences--chart_view_height_unit--" inlineField="<%=true %>"  label="">
						<aui:option value="px" label="px" selected='<%=Validator.isNotNull(chart_view_height_unit)?(("px").equals(chart_view_height_unit)):true %>'/>
						<aui:option value="em" label="em" selected='<%=Validator.isNotNull(chart_view_height_unit)?(("em").equals(chart_view_height_unit)):true %>'/>
					</aui:select>
			</div>
	</aui:fieldset>
	
</liferay-ui:section>
<liferay-ui:section>
	<liferay-ui:error-marker key="errorSection" value="chart.theme" />
		<aui:fieldset label="chart.theme">
			<div class="alert alert-info">
				<span class="displaying-chart-current-theme">
					<liferay-ui:message key="chart.view.config.current.theme" />: <%=Validator.isNotNull(chart_view_theme)?LanguageUtil.get(pageContext, "chart.theme."+chart_view_theme):StringPool.BLANK %>
				</span>
			</div>
			<liferay-util:include page="/html/portlet/chart/view/theme.jsp" servletContext="<%= application %>"></liferay-util:include>
		</aui:fieldset>
</liferay-ui:section>
</liferay-ui:tabs>

	<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />
	<aui:input name="preferences--chart_view_optionid--" type="hidden" value="<%= chart_view_optionid %>" />
	<aui:input name="preferences--chart_view_theme--" type="hidden" value="<%= chart_view_theme %>" />

	<aui:button-row>
		<aui:button type="submit" />
	</aui:button-row>
</aui:form>

<aui:script>
	Liferay.provide(
		window,
		'<portlet:namespace />selectRecordSet',
		function(optionId, titleText) {
			var A = AUI();

			document.<portlet:namespace />fm.<portlet:namespace />chart_view_optionid.value = optionId;
			
			A.one('.displaying-chart-option-id-holder').show();
			A.one('.displaying-help-message-holder').hide();

			var displayRecordSetId = A.one('.displaying-chart-option-id');

			displayRecordSetId.html(titleText + ' (<liferay-ui:message key="modified" />)');
			displayRecordSetId.addClass('modified');
		},
		['aui-base']
	);
	Liferay.provide(
		window,
		'<portlet:namespace />selectTheme',
		function(themeName,themeDisplayName) {
			var A = AUI();
			document.<portlet:namespace />fm.<portlet:namespace />chart_view_theme.value = themeName;
			var displayCurrentTheme = A.one('.displaying-chart-current-theme');
			
			displayCurrentTheme.html('<liferay-ui:message key="chart.view.config.current.theme" />: '+themeDisplayName);
		},
		['aui-base']
	);
</aui:script>